<%@ include file="../common.jsp"%>

<script type="text/javascript">
	$(document).ready(
		
			function() {
				$("#documentCategory").attr("action",'<c:url value="/saveDocCategoryNewDetails.htm"></c:url>');
				$("#docTypeID").val('<c:out value="${docTypeID}"></c:out>');
			});
	
</script>

<c:choose>
	<c:when test="${size eq 0}">
		No Records Found.
	</c:when>
	
	<c:otherwise>
		<form name="submitCategoryToEdit" id="submitCategoryToEdit">
			<div style="width: 60%;">
				<table class="viewDetails" id="viewDetails">
					<c:choose>
						<c:when test="${fn:contains(docTypeCatMap, 'null')}">
							<tr class="message" align="left">
								<td> No Records Found. </td>
							</tr>
						</c:when>
						<c:otherwise>
							<tr class="adminTableMainHeaderColor tableChildHeaderFont">
								<th colspan="4" align="center"><span class="searchResultsCaption" > LIST OF DOCUMENT CATEGORIES(S) </span></th>
							</tr>
							<tr class="even" align="left"> 
								<td colspan="4" align="left">
									Filter by Type: <select id="docTypeID" onchange="filterCategList();">
															<option value="">Choose Type</option>
															<option value="0">ALL</option>
														<c:forEach items="${docTypeMap1}" var="item">
															<option value="${item.key}">${item.value}</option>
														</c:forEach>
													</select>
								</td>
							</tr>
							<tr class="heading" align="center">
								<th> Select </th>
								<th> Category </th>
								<th> Code </th>
								<th> Type </th>
							</tr>	
						
							 <c:forEach var="docTypeMap" items="${docTypeMap}" varStatus="index">
							 	<c:forEach items="${docTypeCatMap[docTypeMap.key]}" var="docCategory">
									<c:set var="tabColor" value="odd"></c:set>
								     	<c:if test="${(index.index % 3) eq 0}">
								        	<c:set var="tabColor" value="even"></c:set>
								        </c:if>
									<tr class="${tabColor}">
										<td align="center"> <input type="radio" id="radio${index.index}" name="myradio" value="${docCategory.dcId},${docCategory.dcName},${docCategory.dcCode},${docTypeMap.key}"/> </td>
										<td>${docCategory.dcName}</td>
										<td>${docCategory.dcCode}</td>
										<td>${docTypeMap.value}</td>
									</tr>	
								 </c:forEach>
							</c:forEach>	
							<table>
							<tr align="center">
								<td colspan="5">
									<input class="formButton ui-corner-all" type="button" value="SELECT" onclick="submitCategoryDetailsForEditing();" />
								</td>
							</tr>
							</table>
							</c:otherwise>
					</c:choose>
				</table>
				
			</div>
		</form>
	
		
		<c:if test="${resultOfSave}">
			Operation Done Successfully.
		</c:if>
		
		<br>
		<hr/>
		<br>
		
		<form:form commandName="documentCategoryDTO" id="documentCategory">
						<form:hidden path="dcId" id="dcId"/>
			<table class="adminFilterTable">
				<tr class="tableChildHeaderColor">
					<th colspan="5"> Edit Document Category Details </th>
				</tr>
				<tr class="formSpacingRow"><td></td> </tr>
				<tr> 
					<td align="left" colspan="5" style="font-family: verdana; font-size: 12px;"> All fields are mandatory.</td> 
				</tr>
				<tr class="formSpacingRow"><td></td> </tr>
				<tr>
					<td class="spacingColumnWidthLess"></td>
					<td class="formLabel"> Category </td>	
					<td class="spacingColumnWidthLess"></td>
					<td class="formField"> <form:input path="dcName" id="dcName"/> 
						 <form:errors path="dcName" cssClass="errorMsg"/> </td>
					<td class="spacingColumnWidthLess"></td>
				</tr>
				<tr class="formSpacingRow"><td></td> </tr>
				<tr>
					<td class="spacingColumnWidthLess"></td>
					<td class="formLabel"> Code </td>	
					<td class="spacingColumnWidthLess"></td>
					<td class="formField"> <form:input readonly="true" path="dcCode" id="dcCode"/> 
						 <form:errors path="dcCode" cssClass="errorMsg"/> </td>
					<td class="spacingColumnWidthLess"></td>
				</tr>
				<tr class="formSpacingRow"><td></td> </tr>
				<tr>
					<td class="spacingColumnWidthLess"></td>
					<td class="formLabel"> Type </td>	
					<td class="spacingColumnWidthLess"></td>
					<td class="formField"> <form:select path="dcParentType.dtId" id="docType">
							<c:forEach var="docTypeList" items="${docTypeList}">
								<form:option value="${docTypeList.dtId}">${docTypeList.dtName}</form:option>
							</c:forEach>
						 </form:select>
						 <form:errors path="dcParentType.dtId" cssClass="errorMsg"/> </td>
					<td class="spacingColumnWidthLess"></td>
				</tr>
				<tr class="formSpacingRow"><td></td> </tr>	
				<tr class="even" align="left">
					<td class="spacingColumnWidthLess"></td>
					<td></td>
					<td class="spacingColumnWidthLess"></td>
					<td colspan="2"> <input class="formButton ui-corner-all" type="button" value="UPDATE" onclick="javascript:addEntity('documentCategory')"> </td>
				</tr>			
				<tr class="formSpacingRow"><td></td> </tr>
			</table>
		</form:form>
	</c:otherwise>
</c:choose>